<?php

namespace App\Controllers\Diary;

use App\Models\Diary\Comment;


class GetLeftComment extends \App\Libs\Base\BaseAction
{
    protected function beforeRun()
    {
        parent::beforeRun();
        //$this->needLogin = TRUE;
    }

    /**
     * @return array 根据活动的期数(period)，返回活动的详情数据；
     */
    public function execute()
    {
        if ($this->request->has('diary')) {
            $diary = $this->request->get('diary');
            $page = $this->request->get('page', 'int', 1);
            $cnum = $this->request->get('cnum', 'int', 5);
            $cmtData = Comment::getCmt($diary, $page, $cnum);
            if (!empty($cmtData)) {
                return \App\Libs\Views\Json::view(0, '成功', array_values($cmtData));
            } else {
                return \App\Libs\Views\Json::view(1, '无评论', []);
            }
        } else {
            return \App\Libs\Views\Json::view(1, '缺少参数', []);
        }
    }
}